package v1

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"github.com/jinzhu/gorm"
	uuid "github.com/satori/go.uuid"
	"goblog/global"
	"goblog/global/Response"
	"goblog/model"
	"goblog/model/request"
	_ "goblog/model/response"
	"goblog/service"
	"goblog/utils"
)

/*
注册
*/
func Register(c *gin.Context) {
	//创建request model
	//var R = request.
	 u := model.SysUser{
		Model:       gorm.Model{},
		UUID:        uuid.UUID{},
		Username:    "zj",
		Password:    "12344",
		NickName:    "ligin",
		HeaderImg:   "",
		Authority:   model.SysAuthority{},
		AuthorityId: "",
	}
	fmt.Println("-----00------")
	service.Register(u)

	Response.Result(Response.SUCCESS, "ligin", "获取成功", c)
	//response := Response.Response{1, res.CommonRes{"admin", 10, "消息"}, "成功"}
}

/*
请求post测试
*/
func PostAuth(c *gin.Context){
	msg := c.PostForm("data")
	
	fmt.Println(msg)
	Response.Result(Response.SUCCESS, msg, "上传成功", c)
}


/*
请求所有用户列表
*/
func UserList(c *gin.Context){

	user := new(model.SysUser)
	var users []model.SysUser
	global.GLOBAL_DB.First(&user)
	global.GLOBAL_DB.Find(&users)

	if len(users) >0 {
		Response.Result(Response.SUCCESS, users, "数据请求成功", c)
	}else{
		var a interface{}
		Response.Result(Response.SUCCESS, a, "数据请求成功", c)
	}
}

func Login(c *gin.Context){

	var login request.RegisterAndLoginStruct  //struct 不带{}表示类型
    _ := c.ShouldBindJSON(login) //绑定struct类型
    //验证是否为空
    UserVerify := utils.Rules{
		"Username" : {utils.NotEmpty()},
		"Password" : {utils.NotEmpty()},
		"Captcha"  : {utils.NotEmpty()},
		"CaptchaId" : {utils.NotEmpty()},
	}

	
}
